import wepy from 'wepy'
export default class extends wepy.mixin {
  data = {
    categories: [],
    activeKey: 0,
    // 屏幕可用高度
    wh: 0,
    // 二级分类列表
    sCates: [],
    scrollTop: 0
  };

  config = {};

  methods = {
    // slidebat切换
    onChange(e) {
      this.sCates = this.categories[e.detail].children
      this.scrollTop--
    },
    // 点击三级列表跳转到商品列表
    goToList(cid) {
      wepy.navigateTo({
        url: `/pages/goods_list?cid=${cid}`
      })
    }
  };

  onLoad() {
    this.getCategories()
    this.getWindowHeight()
  }

  async getCategories() {
    const { data: res } = await wepy.get('/categories')
    wepy.baseToast(res)
    this.categories = res.message
    this.sCates = res.message[0].children
    this.$apply()
  }
  // 动态获取屏幕可用高度
  async getWindowHeight() {
    const res = await wepy.getSystemInfo()
    this.wh = res.windowHeight
    this.$apply()
  }
  onShow() {
    this.$parent.changeBandge()
  }
}